<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ page import="java.sql.*"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
request.setCharacterEncoding("UTF-8");
String meal_name = request.getParameter("meal_name");
String order_num = request.getParameter("order_num");
String cooker_name = request.getParameter("customer_name");
String restaurant_name = request.getParameter("restaurant_name");

try {
    Class.forName("org.mariadb.jdbc.Driver");
    try (Connection conn = DriverManager.getConnection("jdbc:mariadb://localhost:3306/mealdb?user=root&password=1230321");
         PreparedStatement pstmt = conn.prepareStatement("UPDATE dish SET state = ? WHERE meal = ? AND order_num = ?")) {

        pstmt.setString(1, "已完成");
        pstmt.setString(2, meal_name);
        pstmt.setString(3, order_num);


        int rowsUpdated = pstmt.executeUpdate();
        if (rowsUpdated > 0) {
            out.println("更新成功！");
        } else {
            out.println("更新失败！");
        }
        response.sendRedirect("myOrders.jsp?restaurant_name="+ restaurant_name +"&customer_name="+ cooker_name);
    } catch (SQLException e) {
        out.println("数据库操作错误：" + e.getMessage());
    }
} catch (ClassNotFoundException e) {
    out.println("数据库驱动加载失败：" + e.getMessage());
}

%>
</body>
</html>